package com.lanxiao.cloud.common.mybatis.service.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanxiao.cloud.common.mybatis.basic.Entity;
import com.lanxiao.cloud.common.mybatis.service.BaseService;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author ：qiaoliang
 * @date ：2021-08-19
 */
public abstract class BaseServiceImpl <T,Mapper extends BaseMapper<E>,E extends Entity<T>>
    extends ServiceImpl<Mapper,E>
    implements BaseService<T,E> {

  @Override
  public Map<T, E> findByIds(List<T> ids) {
    final QueryWrapper<E> queryWrapper = new QueryWrapper<>();
    queryWrapper.in("id", ids);
    final List<E> es = this.baseMapper.selectList(queryWrapper);
    return es.stream().collect(Collectors.toMap(E::getId, o->o));
  }

}
